<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="testing"; // Database name 
$tbl_name="user";// Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die(" you cannot select DB");

// username and password sent from form 
$teachername=$_POST['teachername']; 
$teacherpass=$_POST['teacherpass'];

// To protect MySQL injection (more detail about MySQL injection)
$teachername = stripslashes($teachername);
$teacherpass= stripslashes($teacherpass);
$teachername= mysql_real_escape_string($teachername);
$teacherpass= mysql_real_escape_string($teacherpass);

$sql="SELECT * FROM $tbl_name WHERE username='$teachername' and password='$teacherpass'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register('teachername');
session_register('teacherpass'); 
header("location:login_success.php");
}
else {
   echo "You had not successfully login ";
echo "You had entered the wrong username or password";
}
?>